import 'package:flutter/material.dart';

void main() =>
    runApp(MyApp(
        setList: new List<String>.generate(100, (i) => '这是第 $i 条数据')
    ));

class MyApp extends StatelessWidget {
  final List<String> setList;
  MyApp({Key key, @required this.setList}) :super(key: key);
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'flutter widget',
      theme: ThemeData(
        //主题色 蓝色
        primarySwatch: Colors.blue,
      ),
      home: Scaffold(
        appBar: new AppBar(
          title: new Text('Flutter之动态ListView'),
          centerTitle: true,
          primary: true, //是否设置内容避开状态栏
        ),
        body: new ListView.builder(
          itemCount: setList.length,
          itemBuilder: (context, index) {
            return new ListTile(
                leading: Icon(Icons.work),
                title: new Text('${setList[index]}')
            );
          },
        ),
      ),
    );
  }
}

class MyList extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return ListView(
      scrollDirection: Axis.horizontal,
      children: <Widget>[
        new Container(
            width: 200.0,
            color: Colors.purple,
            child: new Center(
              child: new Text(
                '这是横向list测试',
                textAlign: TextAlign.center,
                style: TextStyle(fontSize: 30.0, color: Colors.blueAccent),
              ),
            )),
        new Container(
          width: 200.0,
          color: Colors.red,
        ),
        new Container(
          width: 200.0,
          decoration: BoxDecoration(
              image: DecorationImage(
                  image: new AssetImage('images/image-3.jpg'),
                  fit: BoxFit.cover)),
        ),
        new Container(
          width: 200.0,
          color: Colors.blue,
        )
      ],
    );
  }
}
